home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************
- *
- * Editor2.c Defines code for editing within text editor
- *
- * Modification History:
- * 20/2/92 created from scratch.
- *
- *
- *
- *************************************************************************************/
- #include "EditGlobalEqu.p"
-
- #include "Editor2.proto.h"
-
- textEdHdl GetWEditRecord(WindowPtr theWindow);
- lineHdl GetListHead(textEdHdl theEditRec);
- lineHdl GetLinkHandle(lineHdl listHead,int linkID);
- lineHdl NewEmptyLine(int nChars);
- lineHdl GetListTail(textEdHdl theEditRec);
- pascal void ScrollProc(ControlHandle theControl,int partCode);
- char IsEditKind(WindowPtr theWindow);
-
-
- TEHandle GetEditRec(textEdHdl theText)
- {
- /* returns lineEditRec field of text record, which is a textEdit handle */
- if (theText != NIL)
- return((*theText)->lineEditRec);
- else
- return(NIL);
- }
-
-
- textEdHdl GetMasterERecord(TEHandle tRec)
- {
- /* reverse of above- given a text edit record, returns handle of master structure */
-
- GrafPtr owner;
-
- if (tRec != NIL) {
- owner = (*tRec)->inPort;
- if (IsEditKind(owner))
- return(GetWEditRecord(owner));
- }
- return(NIL);
- }
-
-
- InsertLink(lineHdl theLink,lineHdl *head,lineHdl *tail,int afterLink)
- {
- /* inserts new link into chain, after the link with ID afterLink. If afterLink is
- 0, then the link becomes the first link. */
-
- lineHdl next,last,after;
-
- after = GetLinkHandle(*head,afterLink);
- if (theLink != NIL) {
- (*theLink)->lastLine = after;
- if (after != NIL) {
- next = (*after)->nextLine;
- (*after)->nextLine = theLink;
- if (next == NIL)
- *tail = theLink;
- }
- else {
- next = *head;
- *head = theLink;
- }
- (*theLink)->nextLine = next;
- if (next != NIL)
- (*next)->lastLine = theLink;
- }
- }
-
-
- int ReplaceLink(lineHdl newLink,lineHdl *head,lineHdl *tail,int oldLink)
- {
- /* replaces the link with ID = oldLink with the new link. The old one is disposed
- of. If the old link does not exist, this routine does nothing & returns FALSE */
-
- lineHdl oldLk,next,last;
-
- oldLk = GetLinkHandle(*head,oldLink);
- if (oldLk != NIL) {
- next = (*oldLk)->nextLine;
- last = (*oldLk)->lastLine;
- (*newLink)->nextLine = next;
- (*newLink)->lastLine = last;
-
- if (next != NIL)
- (*next)->lastLine = newLink;
- else
- *tail = newLink;
-
- if (last != NIL)
- (*last)->nextLine = newLink;
- else
- *head = newLink;
-
- DisposHandle(oldLk);
- return(TRUE);
- }
- return(FALSE);
- }
-
-
- DeleteLink(lineHdl theLink,lineHdl *head,lineHdl *tail)
- {
- /* deletes link from list, patching as required and modifying head and tail if rqd */
-
- lineHdl next,last;
-
- if (theLink != NIL) {
- next = (*theLink)->nextLine;
- last = (*theLink)->lastLine;
-
- if (next != NIL)
- (*next)->lastLine = last;
- else
- *tail = last;
-
- if (last != NIL)
- (*last)->nextLine = next;
- else
- *head = next;
-
- DisposHandle(theLink);
- }
- }
-
-
- lineHdl MakeLink(TEHandle edRecord,int cCount)
- {
- /* given a text edit record, a link is created of the right size, and the text is
- copied into it. Then the handle is returned for your delectation & delight */
-
- lineHdl theLink = NIL;
- Handle eText;
-
- if (edRecord != NIL) {
- if (cCount > 255)
- cCount = 255;
- theLink = NewEmptyLine(cCount);
- if (theLink != NIL) {
- eText = (*edRecord)->hText;
- HLock(eText);
- HLock((Handle) theLink);
- BlockMove(*eText,&(*theLink)->theLine[1],cCount);
- HUnlock((Handle) theLink);
- HUnlock(eText);
- (*theLink)->theLine[0] = cCount;
- }
- }
- return(theLink);
- }
-
-
- ClickText(WindowPtr theWindow,Point mClick)
- {
- /* when mouse is clicked in text, this function is called to recalculate the selection
- of text, etc. mClick is in local coordinates */
-
- textEdHdl theText;
- Rect pr,tView;
- int line,chLoc,chCnt;
- int margin;
- TEHandle eTxt;
-
- if (IsEditKind(theWindow)) {
- theText = GetWEditRecord(theWindow);
- if (theText != NIL) {
- GetClipRect(theWindow,&pr);
-
- if (PtInRect(mClick,&pr)) {
- /* somewhere in text area, so lets get calculating! We need to know
- the line clicked, and the character in the line */
-
- eTxt = GetEditRec(theText);
- tView = (*eTxt)->viewRect;
- if (PtInRect(mClick,&tView)) {
- /* were clicking the line being edited, so pass click to TE */
-
- }
- else {
- /* were moving to another line */
- margin = GetMarginOffset(theText);
- chLoc = (mClick.h+1 - margin)/(*theText)->mSpace;
- line = ((mClick.v - pr.top)/(*theText)->lineHeight) + (*theText)->topLine;
-
- /* only move it if the line exists! */
-
- }
- }
- }
- }
- }
-
-
-